﻿
<!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->
 <form action="index.php?c=news&a=batch_edit-del&admin=1" method="post" accept-charset="utf-8">
<div class="container">
<div class="row">
<div id="content" class="col-lg-12">
	<!-- PAGE HEADER-->
	<div class="row">
		<div class="col-sm-12">
			<div class="page-header">
				<!-- STYLER -->


				<!-- /STYLER -->
				<!-- BREADCRUMBS -->
				<ul class="breadcrumb">
					<li>
						<i class="fa fa-home"></i>
						<a href="index.html">首页</a>
					</li>
					<li>
						<a href="#">新闻模块</a>
					</li>
					<li>新闻列表</li>
				</ul>
				<!-- /BREADCRUMBS -->
				<div class="clearfix">
					<h3 class="content-title pull-left">新闻列表</h3>
				</div>
			</div>
		</div>
	</div>
	<!-- /PAGE HEADER -->
	<!-- DATA TABLES -->
	<div class="row">
		<div class="col-md-12">
			<!-- BOX -->
			<div class="box border green">


				<div class="box-title">
					<h4><i class="fa fa-table"></i>新闻列表</h4>
					<div class="tools hidden-xs">

						<a href="#box-config" data-toggle="modal" class="config">
							<i class="fa fa-cog"></i>
						</a>
						<a href="javascript:;" class="reload">
							<i class="fa fa-refresh"></i>
						</a>
						<a href="javascript:;" class="collapse">
							<i class="fa fa-chevron-up"></i>
						</a>
						<a href="javascript:;" class="remove">
							<i class="fa fa-times"></i>
						</a>
					</div>
				</div>
				<div class="box-body">
                    <div class="col-sm-12">
                        <div class="pull-right">
                            <div class="dataTables_filter" id="datatable1_filter">
                                <label><input type="text" aria-controls="datatable1" placeholder="Search" class="form-control input-sm"></label>
                            </div>
                        </div>
                        <div class="pull-left">
                            <div id="datatable1_length div" class="dataTables_length">
                                <label>
                                    <select name="nwes" size="1" aria-controls="datatable1" class="form-control input-sm">
                                        <option value="0">请选择</option>
                                        <option value="1">批量删除</option>
                                        <option value="2">批量审核</option>
                                    </select>
                                </label>
                                 <input type="submit"  value="确定" class="btn1"  />
                                 <input type="button" value="取消" class="btn2"  />
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
					<form action="" method="get" accept-charset="utf-8">
					<table style="text-align:center"; id="datatable1" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">

						<thead>
							<tr >
                                <th><input id="All"  name="Fruit" type="checkbox"  value="" />全选
								<th>ID</th>
								<th>新闻标题</th>
								<th class="hidden-xs">新闻类型</th>
								<th>新闻作者</th>
								<th class="hidden-xs">新闻图片</th>
								<th class="hidden-xs">新闻内容</th>
								<th class="hidden-xs">发布者</th>
								<th class="hidden-xs">发布日期</th>
								<th class="hidden-xs">审核</th>
								<th class="hidden-xs">编辑</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($data as $value){ ?>
							<tr class="gradeX" id="div">
                <td width="100"><input name="checked[]" type="checkbox" value="<?php echo $value['id']?>" /></td>
								<td width="100"><?php echo $value['id']?></td>
								<td width="200" class="dbl" title='title' ><?php echo $value['title']?></td>
								<td width="150" class="dbl" title='type' ><?php echo $value['name']?></td>
								<td width="150"><?php echo $value['author']?></td>
								<td width="100"><img  width="60" height="60" src="<?php echo $value['url']?>" alt=""></td>
								<td width="500" class="dbl" title='content' ><?php echo $value['content']?></td>
								<td width="100"><?php echo $value['publisher']?></td>
								<td width="100"><?php echo $value['newstime']?></td>
								<td width="100">
                                    <button type="button" achieve="<?php echo $value['achieve'];?>" class="btn <?php echo ($value['achieve']==1)?'btn-success':'btn-danger';?>  bnt-xs act">
                                    <i class="fa <?php echo $value['achieve']==1?'fa-check':'fa-times';?>"></i></button>
                                   <!--  <button class="btn btn-danger bnt-xs"><i class="fa fa-times"></i></button> -->
                                </td>
								<td width="100">
									<a href="index.php?c=news&a=edit&admin=1&id=<?php echo $value['id']?>" class="btn btn-info"><i class="fa fa-pencil-square-o"></i> 编辑</a>
									<a href="index.php?c=news&a=del&admin=1&id=<?php echo $value['id']?>" onclick="return confirm('真的要删除吗？')"  class="btn btn-2g btn-danger">
									<i class="fa fa-trash-o"></i> 删除</a>
								</td>
							</tr>
							<?php } ?>
						</tbody>
					</table>
				<div class="row"><div class="col-sm-12">
					 <div class="pull-left">
					    <div class="dataTables_info" id="datatable1_info">Showing 1 to 10 of 57 entries</div>
					 </div>
					 <div class="pull-right">
						 <div class="dataTables_paginate paging_bs_full" id="datatable1_paginate">
							   <ul class="pagination">
                                      <?php echo $paget; ?>
							     </ul>
						     </div>
					     </div>
					     <div class="clearfix"></div>
					     </div>
					  </div>
					</form>
				</div>
			</div>
			<!-- /BOX -->
		</div>
	</div>
    </form>
	<!-- /DATA TABLES -->

<script src="resources/admin/js/jquery/jquery-2.0.3.min.js"></script>
	<script type="text/javascript">
$(function(){
        //批量删除/审核全选按钮绑定事件
        $('#All').click(function(){
            if ($(this).is(':checked')) {//not当前选中的
                $('input[type="checkbox"]').not(':checked').prop('checked', true);//not当前位选中的
            }else{
                $('input[type="checkbox"]').prop('checked', false);
             }
        });

        //审核全选按钮绑定事件
        $('.btn1').click(function(){

            // var id = $(this);
            // console.log(id);
             $.ajax({
                url: 'index.php?c=news&a=edit&admin=1',
                type: 'POST',
                //dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
                data: {'achieve': achieve,'id':id},
                success: function(json){
                    // if (json>0) {
                    //      if (achieve>0) {
                    //      obj.removeClass('btn-danger');//删除原来状态类
                    //      obj.addClass('btn-success');//新增状态类
                    //      obj.find('i').removeClass('fa-times');//删除原来图标
                    //      obj.find('i').addClass('fa-check');//增加新图标
                    //      }else{
                    //      obj.removeClass('btn-success');//删除原来状态类
                    //      obj.addClass('btn-danger');//新增状态类
                    //      obj.find('i').removeClass('fa-check');//删除原来图标
                    //      obj.find('i').addClass('fa-times');//增加新图标
                    //      }
                    //    }
               }
            });

        })


  		$('.pagination').on('click','li',function(){
  		var url = $(this).find('a').attr('href');
           $.ajax({
				   type:'get',
				   url:url,
				   dataType:'json',
				   success:function(json){
				   	var data=json.data;
				   	var paget=json.paget;
                    var html='';//给html赋值
         for(i in data) {//使用for in循环，将后台的数据循环获取并拼接显示在td标签中
				var btnclass= data[i].achieve==1?'btn-success':'btn-danger';
                var iclass = data[i].achieve==1?'fa-check':'fa-times';
				html+='<tr class="gradeX">';
                    html+='<td width="100"><input name="input" type="checkbox" value="" /></td>'
					html+='<td width="100">'+data[i].id+'</td>';
					html+='<td width="200" title="title" class="dbl">'+data[i].title+'</td>';
					html+='<td width="150" class="dbl" title="type" >'+data[i].name+'</td>';
					html+='<td width="150">'+data[i].author+'</td>';
					html+='<td width="100"><img width="60" height="60" src="'+data[i].url+'" alt="" /></td>';
					html+='<td width="500" class="dbl" title="content">'+data[i].content+'</td>';
					html+='<td width="100">'+data[i].publisher+'</td>';
					html+='<td width="100">'+data[i].newstime+'</td>';
					html+='<td width="100" class="ach"><button type="button" achieve="'+data[i].achieve+'" class="btn '+btnclass+'  bnt-xs act">';
                    html+='<i class="fa '+iclass+'"></i></button></td>';
					html+='<td width="100">';
						html+='<a href="index.php?c=news&a=edit&admin=1&id='+data[i].id+'" class="btn btn-info">';
						html+='<i class="fa fa-pencil-square-o"></i> 编辑</a>';
						var confirms = "return confirm('真的要删除吗?')";
						html+='<a href="index.php?c=news&a=del&admin=1&id='+'achieve'+'" onclick="'+confirms+'"  class="btn btn-2g btn-danger">';
						html+='<i class="fa fa-trash-o"></i> 删除</a>';
					       html+='</td>';
				html+='</tr>';
         }
					   $('tbody').html(html);//$().html(html);抓取要替换标签的内容替换掉原来的内容
                       $('.pagination').html(paget);
				   }
	          })
            return false;
  		})

  		//双击新闻编辑数据
  		$('tbody').on('dblclick','.dbl',function(){
  			//在tbody标签里面查找input的个数
			var len = $('tbody').find(':text').length;
  			if (len>0) {
  				var v = $('tbody').find(':text').val();
  				$('tbody').find(':text').parent().html(v);
  			};
  			var text = $(this).text();
			var input = '<input type="text" value="'+text+'">';
  			$(this).html(input);
  			$(this).find(':text').focus();
  			$(':text').blur(function(event) {
  				  var value = $(this).val();
  				  //siblings(兄弟)
  				  var id = $(this).parent().siblings('td:eq(1)').text();
  				  var title = $(this).parent().attr('title');
                  $(this).parent().text(value);
            if (value!=text) {
  			$.ajax({
  				type:'post',
  				url:'index.php?c=news&a=edit&id='+id,
  				data:{'title':title,'val':value,'achieve':'-1'},
  				success:function(len){
  					if (len>0) {
  						alert('修改成功');
  					}else{
  						alert('修改失败');
  					}

  				      }
  			       })
                }
  			});
  		});


      // 状态按钮事件绑定
      $('tbody').on('click','button.act',function(){
        // alert(1);return;
        var id = $(this).parent().parent().find('td:eq(1)').text();

        // alert(id);return;
        if ($(this).attr('achieve')>0){
            var achieve=0;
        }else{
            var achieve=1;
        }
        //修改BOTTON标签状态属性值
        $(this).attr('achieve',achieve);
        //把当前操作存在临时变量中
        var obj = $(this);
        $.ajax({
            url: 'index.php?c=news&a=edit&admin=1',
            type: 'POST',
            //dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
            data: {'achieve': achieve,'id':id},
            success:function(json){
               if (json>0) {
                 if (achieve>0) {
                 obj.removeClass('btn-danger');//删除原来状态类
                 obj.addClass('btn-success');//新增状态类
                 obj.find('i').removeClass('fa-times');//删除原来图标
                 obj.find('i').addClass('fa-check');//增加新图标
                 }else{
                 obj.removeClass('btn-success');//删除原来状态类
                 obj.addClass('btn-danger');//新增状态类
                 obj.find('i').removeClass('fa-check');//删除原来图标
                 obj.find('i').addClass('fa-times');//增加新图标
                 }
               }
            }
        })
      })

     });
	</script>



